*******************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Table 3: State IRCA and state political outcomes
*******************************

	//Load data
	use  state_irca_congress.dta, clear
	
	//Controls
	global state_controls c.state_pop1990#i.p102_full c.income_state_pc1990#i.p102_full  c.age_share_state1990#i.p102_full c.state_unemployment1990#i.p102_full c.state_blackshare1990#i.p102_full c.state_whiteshare1990#i.p102_full c.state_births#i.p102_full c.educ_state1990#i.p102_full 

	//Controls
	global state_controls_full c.state_pop1990##i.p102_full##i.legal_control_kaplan1991 c.income_state_pc1990##i.p102_full##i.legal_control_kaplan1991  c.age_share_state1990##i.p102_full##i.legal_control_kaplan1991 c.state_unemployment1990##i.p102_full##i.legal_control_kaplan1991 c.state_blackshare1990##i.p102_full##i.legal_control_kaplan1991 c.state_whiteshare1990##i.p102_full##i.legal_control_kaplan1991 c.state_births##i.p102_full##i.legal_control_kaplan1991 c.educ_state1990##i.p102_full##i.legal_control_kaplan1991 
	
	
	//Drop Single District States in 1990
	drop if single_district1990==1 
		
	//VRA Control
	global vra_control i.vra_state#i.p102_full
	
	//Total Analogous
	global fe_1  i.congress c.hisp_share_state1980#i.p102_full
	
*********
* Report 
*********
	estimates clear
	
	//Hispanic Reps
	reghdfe hisp_reps $state_controls $vra_control $fe_1  c.state_irca_total_pc_std##i.p102_full##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster(StateFIPS)
	sum hisp_reps if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102_full#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
		lincom 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	 boottest 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p_sum = r(p)
	eststo 
	
		
	//DW Nominate
	reghdfe nominate_dim1_med $state_controls $vra_control  $fe_1 c.state_irca_total_pc_std##i.p102_full##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster(StateFIPS)
	sum nominate_dim1_med if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102_full#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
		lincom 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	 boottest 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p_sum = r(p)
	eststo 
	
	//Dems in Delegation
	reghdfe dem_representatives $state_controls $vra_control $fe_1 c.state_irca_total_pc_std##i.p102_full##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster(StateFIPS)
	sum dem_representatives if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102_full#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
	lincom 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	 boottest 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p_sum = r(p)
	eststo 
	
	//Efficiency Gap
	reghdfe state_eg $state_controls $vra_control $fe_1  c.state_irca_total_pc_std##i.p102_full##ib2.legal_control_kaplan1991 [weight=state_pop1990], a(StateFIPS) cluster(StateFIPS)	
	sum state_eg if e(sample) & p102_full==0
	estadd scalar ymean = r(mean)
	estadd scalar ysd = r(sd)
	estadd scalar clusters = e(N_clust)
	 boottest c.state_irca_total_pc_std#1.p102_full#1.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p1 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full#0.legal_control_kaplan1991, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p0 = r(p)
	 boottest c.state_irca_total_pc_std#1.p102_full, seed(5) cluster(StateFIPS) boot(wild) nograph
	estadd scalar boot_p2 = r(p)
	lincom 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std
	estadd scalar sum_1 = r(estimate)
	estadd scalar p_sum = r(p)
	 boottest 1.p102_full#c.state_irca_total_pc_std + 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std = 0, seed(5) cluster(StateFIPS) boot(wild) nograph
	 estadd scalar boot_p_sum = r(p)
	eststo 

//Report Table
	estfe est*
	esttab est*  	using "tab3.tex", replace booktabs ///
					 nonote noobs nogaps compress noeqlines substitute(_ _) ///
					 mgroups("Descriptive Representation" "Substantive Representation" "Efficiency", pattern(1 1 0 1) ///
				prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
					mtitles("\makecell{Hispanics \\ in Delegation}" "\makecell{Median \\ DW-Nominate}" "\makecell{Democrats \\ in Delegation}" "\makecell{E. \\ Gap}") sfmt(%9.2gc) se ///
					scalars("N $N$" "clusters Clusters" "ymean $\bar{Y}_{102}$" "ysd $[S.D.]$" "boot_p2 Bootstrap IRCA x Post"  "boot_p1 Bootstrap IRCA x Post x D") ///
					keep(1.p102_full#c.state_irca_total_pc_std 1.p102_full#1.legal_control_kaplan1991#c.state_irca_total_pc_std) label star(* 0.1 ** 0.05 *** 0.01) 
			
